<!doctype html>
<html class="no-js" lang="zxx">


<?php
				session_start();
                $user = 'root';
                $pass = '';
                $dbh = new PDO('mysql:host=localhost;dbname=doctor', $user, $pass);
?>


<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Частная клиника имени Лазарева</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- <link rel="manifest" href="site.webmanifest"> -->
    <link rel="shortcut icon" type="image/x-icon" href="img/favicon.png">
    <!-- Place favicon.ico in the root directory -->

    <!-- CSS here -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/owl.carousel.min.css">
    <link rel="stylesheet" href="css/magnific-popup.css">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/themify-icons.css">
    <link rel="stylesheet" href="css/nice-select.css">
    <link rel="stylesheet" href="css/flaticon.css">
    <link rel="stylesheet" href="css/gijgo.css">
    <link rel="stylesheet" href="css/animate.css">
    <link rel="stylesheet" href="css/slicknav.css">
    <link rel="stylesheet" href="css/style.css">
</head>

<body>
    <header>
        <div class="header-area ">
            <div class="header-top_area">
                <div class="container">
                    <div class="row">
                        <div class="col-xl-6 col-md-6 ">
                            <div class="social_media_links">
                                <a href="#">
                                    <i class="fa fa-linkedin"></i>
                                </a>
                                <a href="#">
                                    <i class="fa fa-facebook"></i>
                                </a>
                                <a href="#">
                                    <i class="fa fa-google-plus"></i>
                                </a>
                            </div>
                        </div>
                        <div class="col-xl-6 col-md-6">
                            <div class="short_contact_list">
                                <ul>
                                    <li><a href="#"> <i class="fa fa-envelope"></i> info@medlazarev.com</a></li>
                                    <li><a href="#"> <i class="fa fa-phone"></i> 16-18-20</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div id="sticky-header" class="main-header-area">
                <div class="container">
                    <div class="row align-items-center">
                        <div class="col-xl-3 col-lg-2">
                            <div class="logo">
                                <a href="index.php">
                                    <img src="img/blog/logo.png" alt="">
                                </a>
                            </div>
                        </div>
                        <div class="col-xl-6 col-lg-7">
                            <div class="main-menu  d-none d-lg-block">
                                <nav>
                                    <ul id="navigation">
                                        <li><a class="active" href="index.php">Главаня</a></li>
                                        <li><a href="Department.php">Услуги</a></li>
                                        <li><a href="Doctors.php">Врачи</a></li>
                                        <li><a href="contact.php">Контакты</a></li>
                                    </ul>
                                </nav>
                            </div>
                        </div>
                        <div class="col-xl-3 col-lg-3 d-none d-lg-block">
                            <div class="Appointment">
                                <div class="book_btn d-none d-lg-block">
                                    <a href="zapis.php">Записаться на приём</a>
                                </div>
                            </div>
                        </div>
                        <div class="col-12">
                            <div class="mobile_menu d-block d-lg-none"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </header>

	<center>
        <div class="popup_box ">
            <div class="popup_inner">
                <h3>Запись на приём</h3>
                <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
                    <div class="row">
                        <div class="col-xl-6">
                            <input type="date" placeholder="Выберите дату" name="zap_date">
                        </div>
                        <div class="col-xl-6">
<?php
  $sql = "SELECT * FROM `uslugi`";
  $result_select = mysqli_query($on_link, $sql);
  
  	echo "<select class='form-select wide' id='default-select' name = 'zap_usluga'>";
  	echo "<option data-display='Выберите услугу'>Услуги:</option>";
  		while($object = mysqli_fetch_object($result_select)){
	echo "<option value = '$object->name_usluga' > $object->name_usluga </option>";}
  	echo "</select>";
?>	
                        </div>
                        <div class="col-xl-6">
<?php
  $sql = "SELECT * FROM `doctors`";
  $result_select = mysqli_query($on_link, $sql);
  
  	echo "<select class='form-select wide' id='default-select' name = 'zap_docname'>";
  	echo "<option data-display='Выберите врача'>Врачи:</option>";
  		while($object = mysqli_fetch_object($result_select)){
	echo "<option value = '$object->doctor_name' > $object->doctor_name </option>";}
  	echo "</select>";
?>
                        </div>
                        <div class="col-xl-6">
                            <input type="text"  placeholder="Введите ФИО" name="zap_pacient">
                        </div>
                        <div class="col-xl-6">
                            <input type="text"  placeholder="Введите номер" name="zap_phone">
                        </div>
                        <div class="col-xl-6">
                            <input type="email"  placeholder="Email" name="zap_email">
                        </div>
                        <div class="col-xl-12">
                            <button type="submit" class="btn btn-primary">Отправить</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
	</center>
    <!-- form itself end -->

	

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
	if(empty($_POST["zap_date"]))
		die('Пришли не все данные');
	if(empty($_POST["zap_usluga"]))
		die('Пришли не все данные');
	if(empty($_POST["zap_docname"]))
		die('Пришли не все данные');
	if(empty($_POST["zap_pacient"]))
		die('Пришли не все данные');
	if(empty($_POST["zap_phone"]))
		die('Пришли не все данные');
	if(empty($_POST["zap_email"]))
		die('Пришли не все данные');
	
    $zapis_date = test_input($_POST["zap_date"]);
    $zapis_usluga = test_input($_POST["zap_usluga"]);
    $zapis_docname = test_input($_POST["zap_docname"]);
	$zapis_pacient = test_input($_POST["zap_pacient"]);
	$zapis_phone = test_input($_POST["zap_phone"]);
	$zapis_email = test_input($_POST["zap_email"]);
	
	$sth = $dbh->prepare(
    "INSERT INTO 
                `zapisi`(`zapis_date`, `zapis_usluga`, `zapis_docname`, `zapis_pacient`, `zapis_phone`, `zapis_email`) 
            VALUES 
                (:zapis_date, :zapis_usluga, :zapis_docname, :zapis_pacient, :zapis_phone, :zapis_email)
            ");
	$sth->execute(array('zapis_date' => $zapis_date,
						'zapis_usluga' => $zapis_usluga,
						'zapis_docname' => $zapis_docname,
						'zapis_pacient' => $zapis_pacient,
						'zapis_phone' => $zapis_phone,
						'zapis_email' => $zapis_email));

	echo "Записан!";
}
	function test_input($data) {
		$data = trim($data);
		$data = stripslashes($data);
		$data = htmlspecialchars($data);
		return $data;
	}

?>	


    <!-- JS here -->
    <script src="js/vendor/modernizr-3.5.0.min.js"></script>
    <script src="js/vendor/jquery-1.12.4.min.js"></script>
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/owl.carousel.min.js"></script>
    <script src="js/isotope.pkgd.min.js"></script>
    <script src="js/ajax-form.js"></script>
    <script src="js/waypoints.min.js"></script>
    <script src="js/jquery.counterup.min.js"></script>
    <script src="js/imagesloaded.pkgd.min.js"></script>
    <script src="js/scrollIt.js"></script>
    <script src="js/jquery.scrollUp.min.js"></script>
    <script src="js/wow.min.js"></script>
    <script src="js/nice-select.min.js"></script>
    <script src="js/jquery.slicknav.min.js"></script>
    <script src="js/jquery.magnific-popup.min.js"></script>
    <script src="js/plugins.js"></script>
    <script src="js/gijgo.min.js"></script>
    <!--contact js-->
    <script src="js/contact.js"></script>
    <script src="js/jquery.ajaxchimp.min.js"></script>
    <script src="js/jquery.form.js"></script>
    <script src="js/jquery.validate.min.js"></script>
    <script src="js/mail-script.js"></script>

    <script src="js/main.js"></script>
    <script>
        $('#datepicker').datepicker({
            iconsLibrary: 'fontawesome',
            icons: {
                rightIcon: '<span class="fa fa-caret-down"></span>'
            }
        });
        $('#datepicker2').datepicker({
            iconsLibrary: 'fontawesome',
            icons: {
                rightIcon: '<span class="fa fa-caret-down"></span>'
            }

        });
    $(document).ready(function() {
    $('.js-example-basic-multiple').select2();
});
    </script>
</body>

</html>